<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>在线编辑工具</title>
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script type="text/javascript" src="./js/codemirror.min.js"></script>
    <script type="text/javascript" src="./js/shell.js"></script>
    <script type="text/javascript" src="./js/sweetalert2.js"></script>
    <link rel="stylesheet" type="text/css" href="./css/codemirror.min.css">
    <link rel="stylesheet" type="text/css" href="./css/twilight.css">
    <link rel="stylesheet" type="text/css" href="./css/dracula.css">
    <link rel="stylesheet" type="text/css" href="./css/main.css">
</head>

<body>
    <div class="container">
        <div class="diffs">
            <nav>
                <ul>
                    <li><a href="./home">首页</a></li>
                    <li class="active"><a href="./crontab">定时设定</a></li>
                    <li><a href="./diff">对比工具</a></li>
                    <li><a href="./shareCode">Share Code</a></li>
                    <li><a href="./diy">自定义脚本</a></li>
                    <li><a href="./log">日志查询</a></li>
                    <li><a href="./changepwd">修改密码</a></li>
                    <li><a href="./logout">退出</a></li>
                </ul>
            </nav>
            <header>
                <h1>在线编辑工具</h1>
                <button id="save" title="保存">保存 crontab.list</button>
            </header>
            <h4>crontab.list</h4>
            <div class="wrapper">
                <textarea id="code" name="code"></textarea>
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
                lineNumbers: true,
                lineWrapping: true,
                styleActiveLine: true,
                matchBrackets: true,
                mode: 'shell',
                theme: 'dracula'
            });
            let timeStamp = Date.now();
            $.get("./api/config/crontab?t="+timeStamp, function (data) {
                editor.setValue(data);
            });

            $('#save').click(function () {
                var confContent = editor.getValue();
                let timeStamp = Date.now();
                $.post('./api/save?t='+timeStamp, { content: confContent, name: "crontab.list" }, function (data) {
                    let icon = (data.err == 0) ? "success" : "error"
                    Swal.fire({
                        title:data.title,
                        html: data.msg + '<br>❤️🧡定时任务已同步更新🧡❤️',
                        icon: icon
                    }).then((result) => {
                        window.location.reload(true);
                    })
                });
            });
        });

    </script>

</body>

</html>
